package com.tony.pmp.common.utils;

import org.apache.commons.lang.StringUtils;

import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: CommonUtil
 * @Auther: 皮蛋布丁
 * @Date: 2021/07/18/23:08
 * @Description: 字符串拼接处理
 */
public class CommonUtil {

    public static String randomUUID(){
        return UUID.randomUUID().toString().replaceAll("-","");
    }

    /**
    * @Description: concatStrToChar 分隔后拼接成用于sql查询的字符串- 'a','b','c'  "a,b,c"
    * @Param: [param, separatorChars]
    * @return: java.lang.String
    * @Author: 皮蛋布丁
    * @Date: 2021/7/18 23:10
    */
    public static String concatStrToChar(String param, String separatorChars){
        StringBuilder sb=new StringBuilder();
        String[] arr= StringUtils.split(param,separatorChars);
        int i=0;
        for (;i<arr.length;i++){
            if (arr.length-1 != i){
                sb.append("'").append(arr[i]).append("'").append(",");
            }else{
                sb.append("'").append(arr[i]).append("'");
            }
        }
        return sb.toString();
    }

    /**
    * @Description: concatStrToInt 分隔后拼接成用于sql查询的字符串- a,b,c
    * @Param: [param, separatorChars]
    * @return: java.lang.String
    * @Author: 皮蛋布丁
    * @Date: 2021/7/18 23:10
    */
    public static String concatStrToInt(String param, String separatorChars){
        StringBuilder sb=new StringBuilder();
        String[] arr= StringUtils.split(param,separatorChars);
        int i=0;
        for (;i<arr.length;i++){
            if (arr.length-1 != i){
                sb.append(arr[i]).append(",");
            }else{
                sb.append(arr[i]);
            }
        }
        return sb.toString();
    }

//    public static void main(String[] args) {
//        String params="1,2,3,4,5";
//        System.out.println(concatStrToInt(params,","));
//
//        params="R1010,R1020,R1030";
//        System.out.println(concatStrToChar(params,","));
//    }
}
